package yingyong;

import gongju.DBUtil;
import pickaging.HouseInfo;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

@WebServlet("/select")
public class Select extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf8");
        response.setContentType("text/html;charset=utf8");
        String sql = "select * from house_info i left join house_type t on i.house_type_id = t.id";
        try {
        ResultSet re = DBUtil.query(sql);
        ArrayList<HouseInfo> list = new ArrayList<>();
            while (re.next()){
                int id = re.getInt(1);
                int typeid = re.getInt(6);
                String mode = re.getString(2);
                double rent = re.getDouble(3);
                String cont = re.getString(4);
                String depo = re.getString(5);
                String addr = re.getString(7);
                int tid = re.getInt(8);
                String type = re.getString(9);
                HouseInfo hi = new HouseInfo(id, mode, rent, cont, depo, tid, addr);
                list.add(hi);
            }
            request.setAttribute("list",list);
            request.getRequestDispatcher("WEB-INF/list.jsp").forward(request,response);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
